package com.nexttwist.datamanager;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nexttwist.model.Registration;
import com.nexttwist.model.Song;
import com.nexttwist.model.SongSummary;
import com.nexttwist.model.Track;
import com.nexttwist.util.Util;

public class SongManager implements ISongManager{
	
	Util util = new Util();

	@Override
	public boolean register(Registration registration) throws Exception {
		// Call API
		return true;
	}

	@Override
	public boolean login(String userName, String password) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Song createSong(String title, Track track) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Song getSong(String songId, Context context) throws Exception {
		util.setContext(context);
		
		String jsonResponse = util.loadJSONFromAsset("song.json");
		Gson gson = new Gson();
		Song song = gson.fromJson(jsonResponse, Song.class);
			
		return song;
	}
	
	@Override
	public Track saveTrack(String title, Track track) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Song addEntryTrack(Track track) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<SongSummary> getHotSong(Context context) throws Exception {

		util.setContext(context);
		
		String jsonResponse = util.loadJSONFromAsset("hotsongs.json");
		Gson gson = new Gson();
		List<SongSummary> hotSongs = gson.fromJson(jsonResponse, new TypeToken<ArrayList<SongSummary>>(){}.getType());
			
		return hotSongs;
	}

}
